package com.atguigu.eduservice.controller;


import com.atguigu.common.R;
import com.atguigu.eduservice.entity.tree.TreeEntity;
import com.atguigu.eduservice.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Panghl
 * @since 2021-01-04
 */
@Api(tags = {"课程分类"})
@RestController
@RequestMapping("/eduservice/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @ApiOperation(value = "添加课程分类，获取上传过来的文件，把文件内容读取出来")
    @PostMapping("/addSubject")
    public R addSubject(MultipartFile file){
        //上传过来的excel文件
        subjectService.saveSubject(file,subjectService);
        return R.ok();
    }

    @ApiOperation(value = "返回树形结构")
    @GetMapping("/getAllSubject")
    public R getAllSubject(){
        List<TreeEntity> list = subjectService.getAllSubject();
        return R.ok().data("list",list);
    }

}
